import type {
    ColDef
} from '@ag-grid-community/core';

import {
    LargeTextEditor,
} from '@/components/table/components/edit';

import {
    setupEditablePage as setupPage0,
} from '@/components/table/lib';

import {
    tf,
    auditStatusCol,
} from '@/components/table/lib';


interface SetupPageConfig {
    getDataApiUrl: string,
    submitChangedDataApiUrl: string,
    columnDefs: ColDef[]
}

export function setupPage(config: SetupPageConfig) {
    setupPage0({
        getDataApiUrl: config.getDataApiUrl,
        submitChangedDataApiUrl: config.submitChangedDataApiUrl,
        getOptions: (manager) => ({
            columnDefs: config.columnDefs
                .concat([
                    {
                        ...auditStatusCol({
                            field: 'status',
                            editable: true
                        }),
                        onCellValueChanged: (params) => manager.onCellValueChanged(params),
                    },
                    {
                        ...tf("comment", "批注"),
                        type: 'editable',
                        onCellValueChanged: (params) => manager.onCellValueChanged(params),
                        cellEditor: LargeTextEditor,
                        minWidth: 120,
                        flex: 1,
                    },
                    {
                        ...tf("auditor", "审核者"),
                        width: 120,
                    },
                    {
                        ...tf("updated_at", "审核日期"),
                    }
                ])
        })
    });
}
